


def prime(bruh):
    off = True
    for auch in range(2, int(bruh ** 0.5)+1):
        if bruh % auch == 0:
            off = False
            break
    return off


lozer = int(input())
if lozer < 1000 or lozer > 9999:
    print(0)
else:
    so2 = str(lozer)
    cs2 = 0
    for txt in range(len(so2)):
        for umnik in range(txt+1, len(so2)+1):
            caps = int(so2[txt:umnik])
            if prime(caps):
                cs2 = max(cs2, caps)



    print(cs2)